<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        #pic{
            width:100px;
            height:100px;
            border-radius:50% ;
            margin:20px auto;
            cursor: pointer;
        }
        #pic1{
            width:100px;
            height:100px;
            border-radius:50% ;
            margin:20px auto;
            cursor: pointer;
        }
    </style>
    <script src="js/jquery-1.12.2.min.js"></script>
    <script>
        $(function() {
            $("#pic").click(function () {
                $("#upload").click(); //隐藏了input:file样式后，点击头像就可以本地上传
                $("#upload").on("change",function(){
                    var objUrl = getObjectURL(this.files[0]) ; //获取图片的路径，该路径不是图片在本地的路径
                    if (objUrl) {
                        $("#pic").attr("src", objUrl) ; //将图片路径存入src中，显示出图片
                    }
                });
            });
        });

        $(function() {
            $("#pic1").click(function () {
                $("#upload1").click(); //隐藏了input:file样式后，点击头像就可以本地上传
                $("#upload1").on("change",function(){
                    var objUrl = getObjectURL(this.files[0]) ; //获取图片的路径，该路径不是图片在本地的路径
                    if (objUrl) {
                        $("#pic1").attr("src", objUrl) ; //将图片路径存入src中，显示出图片
                    }
                });
            });
        });

        //建立一個可存取到該file的url
        function getObjectURL(file) {
            var url = null ;
            if (window.createObjectURL!=undefined) { // basic
                url = window.createObjectURL(file) ;
            } else if (window.URL!=undefined) { // mozilla(firefox)
                url = window.URL.createObjectURL(file) ;
            } else if (window.webkitURL!=undefined) { // webkit or chrome
                url = window.webkitURL.createObjectURL(file) ;
            }
            return url ;
        }
    </script>
</head>
<body>
<img id="pic" src="images/ex.png" >
<input id="upload" name="file" accept="image/*" type="file" style="display: none"/>
<img id="pic1" src="images/ex.png" >
<input id="upload1" name="file" accept="image/*" type="file" style="display: none"/>
</body>
</html>